package gb.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import gb.demo.entity.Label;
import gb.demo.entity.Movie;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MovieMapper extends BaseMapper<Movie> {
    @Select("select movielabel.labelid,label.labelname from movielabel LEFT JOIN label ON movielabel.labelid = label.labelid where movieid = #{movieid}")
    List<Label> findMovieLabel(@Param("movieid") String movieid);

    @Select("SELECT distinct movie.* FROM (movie LEFT JOIN movielabel ON movie.movieid=movielabel.movieid LEFT JOIN userdescrip ON movielabel.labelid=userdescrip.labelid) WHERE userdescrip.userid=#{userid} GROUP BY movieid ORDER BY(rate * 0.4 + heat *0.000002 + weight*0.8)DESC LIMIT 50")
    List<Movie> recommend(@Param("userid") int userid);
//    get top 50
    @Select("SELECT * FROM `movie` ORDER BY heat DESC LIMIT 20")
    List<Movie> getTop20();
    @Select("SET sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';")
    void set();
    @Select("SELECT * FROM `movie` where updateyear =#{updateyear}")
    List<Movie> movieGoroup(@Param("updateyear") String updateyear);

    @Select("SELECT * FROM `movie` where movieid IN (select movieid from movielabel where labelid=#{labelid})AND updateyear=#{updateyear}")
    List<Movie> movieGroupLabelAndYear(@Param("updateyear") String updateyear,@Param("labelid") String labelid);
}
